﻿CREATE PROCEDURE QIC.LongPrint @String NVARCHAR(MAX)
AS
BEGIN
	DECLARE @CurrentEnd BIGINT
	DECLARE @Offset tinyint

	SET @String = replace(  replace(@string, char(13) + char(10), char(10))   , char(13), char(10))

	WHILE LEN(@String) > 1
	BEGIN
		IF CHARINDEX(CHAR(10), @String) between 1 AND 4000
		BEGIN
			SET @CurrentEnd =  CHARINDEX(char(10), @String) -1
			SET @Offset = 2
		END
		ELSE
		BEGIN
			SET @CurrentEnd = 4000
			SET @Offset = 1
		END   
		PRINT SUBSTRING(@String, 1, @CurrentEnd) 
		set @string = SUBSTRING(@String, @CurrentEnd+@Offset, LEN(@String))   
	END 

END